/**
 * 作者: hwp
 * 日期: 2025-05-21 10:34:20
 * 备注: 联盟互助列表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.server.game.base.AllParam;
import com.motu.monstercity.server.game.commondata.union.UnionConstant;
import com.motu.monstercity.server.game.commondata.union.UnionMain;
import com.motu.monstercity.server.game.logic.BuildManager;
import com.motu.monstercity.server.game.logic.UnionManager;
import com.motu.monstercity.server.game.logic.WorldManager;
import com.motu.vertx.module.utility.toolset.TimeUtils;

import java.util.List;

public class UnionReciprocityList extends UnionReciprocityListModel {
    public UnionReciprocityList() {
        super();
    }

    public UnionReciprocityList(long unionId, long userId, int type, long seekId, String uniqeId, int helpNumMax) {
        putUnionId(unionId);
        putUserId(userId);
        putType(type);
        putActivateTime(TimeUtils.getCurTime());
        putSeekId(seekId);
        putUniqeId(uniqeId);
        putHelpNumMax(helpNumMax);
    }

    // 判断这个求助信息是否可以进行帮助
    public boolean isCanHelp(long uid, List<UserUnionReciprocityRecord> recordList, UnionInfo unionInfo) {
        if (uid == getUserId()) {
            return false;// 自己不能帮助自己
        }
        for (UserUnionReciprocityRecord record : recordList) {
            if (record.getReciprocityId() == getId()) {
                return false;// 已经帮助过了
            }
        }

        UnionMain unionMain = UnionManager.getUnionMain(unionInfo.getLevel());
        if (unionMain == null || getHelpNum() >= getHelpNumMax()) {// 被帮助次数达到上限了
            return false;
        }

        return true;
    }

    // 判断该求助的事件是否已经完成，行军完成，或是治疗已经完成
    public boolean isEventComplte() {
        long userId = getUserId();
        // 大世界行军事件
        if (getType() == UnionConstant.UNION_RECIPROCITY_TYPE_1 || getType() == UnionConstant.UNION_RECIPROCITY_TYPE_2) {
            UserWorldTeam userWorldTeam = WorldManager.getUserWorldTeam(userId, (int)getSeekId());
            if (userWorldTeam == null) {
                return true;
            }
            if (!getUniqeId().equals(userWorldTeam.getUniqeId())) {
                return true;
            }
            if (TimeUtils.getTimeDiff(userWorldTeam.getUpdateTime()) + userWorldTeam.getReduceTime() > userWorldTeam.getTimeLeft()) {
                return true;
            }
        } else if (getType() == UnionConstant.UNION_RECIPROCITY_TYPE_3) {// 治疗事件
            UserSoldierRecover userSoldierRecover = BuildManager.getUserSoldierRecover(userId);
            if (userSoldierRecover == null) {
                return true;
            }
            if (!getUniqeId().equals(userSoldierRecover.getUniqeId())) {
                return true;
            }
        }
        return false;
    }
}
